package com.simba.server.jsonservice.serivces;

import com.simba.server.components.CommandExecutor;
import com.simba.server.components.SortControllerManager;
import org.apache.log4j.Logger;
import org.jboss.netty.channel.Channel;
import org.json.JSONObject;


import com.simba.common.jsonservice.JsonService;
import com.simba.common.log.LogUtil;

import com.simba.server.commands.impl.web.WebSlotStatusCmd;
import com.simba.server.components.SlotManager;
import com.simba.server.components.SortCommonDefines;
import com.simba.server.components.data.SlotInfo;

/**
 * Created by kavin on 16-3-30.
 */
public class UnLockSlotJsonService implements JsonService
{
	public static final String NAME = "UnLockSlot";
	private final static Logger logger = Logger.getLogger(UnLockSlotJsonService.class);

	@Override
	public void handleRequest(Channel channel, Object content)
	{
		try
		{
			JSONObject request = (JSONObject) content;
			String slotId = request.getString("slotId");
			String type = request.getString("type");

			SlotInfo slotInfo = SlotManager.getInstance().getSlotInfo(slotId);

			if (slotInfo != null)
			{
				slotInfo.setSlotType("1");
				if (type.equals("packet")){
					SortControllerManager.getInstance().onSlotUnlockMessage(slotInfo);
				}else {
					slotInfo.setLockStatus(SortCommonDefines.SLOT_SOFT_UNLOCK_FLAG);
					CommandExecutor.executorWebCommand(WebSlotStatusCmd.NAME, slotInfo,false);
				}
			}
		}
		catch (Exception e)
		{
			LogUtil.LogError(UnLockSlotJsonService.logger, "UnLock Slot Error " + e.getMessage());
		}

	}
}
